import * as zrender from 'zrender';
import { initLastScrollX } from '../config';
import { mockRandomPersons, mockRandomShifts } from '../utils/helper';
import { useCalendarStore } from '../../stores/calendar';

/**
 * 初始化ZRender实例
 */
export function initializeZRender() {
  const zr = zrender.init(document.getElementById('zrender-container'), {
    renderer: 'canvas',
  });
  return zr;
}

/**
 * 初始化人员排班数据
 * @returns {PersonSchedule[]} 人员排班数组
 */
export function initializePersonSchedules(): PersonSchedule[] {
  const calendarStore = useCalendarStore();
  const startDate = new Date(calendarStore.dateRange.start);
  const todayOffset = Math.floor((+new Date() - +startDate) / (60 * 60 * 24 * 1000));

  const persons = mockRandomPersons(10);
  const schedules = persons.map(person => ({
    person,
    shifts: mockRandomShifts(person.id, Math.floor(Math.random() * 4) + 1, todayOffset),
  }));

  return schedules;
}

/**
 * 初始化滚动位置
 * @returns {ScrollState} 滚动状态对象
 */
export function initializeScrollPosition(): ScrollState {
  return {
    lastScrollX: initLastScrollX,
    lastScrollY: 0,
  };
}
